package com.example.mcmurphy.startproject_115wxy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.mcmurphy.startproject_115wxy.Iface.WeatherListener;
import com.example.mcmurphy.startproject_115wxy.bean.Weatherinfo;
import com.example.mcmurphy.startproject_115wxy.model.Weathermodel;

public class MainActivity extends AppCompatActivity implements WeatherListener,View.OnClickListener{
    private EditText etcity;
    private Button btnfind1,btnfind2;
    private TextView tvcityname,windwd,temp,windsd,windws;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init()
    {
        etcity=(EditText)findViewById(R.id.editText);
        btnfind1=(Button)findViewById(R.id.button);
        btnfind2=(Button)findViewById(R.id.button2);
        tvcityname=(TextView)findViewById(R.id.textView4);
        windwd=(TextView)findViewById(R.id.textView13);
        windsd=(TextView)findViewById(R.id.textView3);
        windws=(TextView)findViewById(R.id.textView15);
        temp=(TextView)findViewById(R.id.textView11);
        btnfind1.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }


    @Override
    public void onResponse(Weatherinfo weatherinfo) {
        if (weatherinfo!=null)
        {
            tvcityname.setText(weatherinfo.getCity());
            temp.setText(weatherinfo.getTemp());
            windwd.setText(weatherinfo.getWD());
            windsd.setText(weatherinfo.getSD());
            windws.setText(weatherinfo.getWS());
        }
    }

    @Override
    public void onFail(String msg) {
        tvcityname.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId())
        {
            case R.id.button:
                System.out.println("----- 按钮1被点击");
                Weathermodel weatherModel=new Weathermodel();
                weatherModel.getWeather(etcity.getText().toString(),this);
                break;
            case R.id.button2:
                System.out.println("-----按钮2被点击");
                Weathermodel weather51Model=new Weathermodel();
                weather51Model.getWeather(etcity.getText().toString(),this);
                break;
        }
    }
}